#include <stdio.h>
#include <errno.h>
#include <string.h>
#include <unistd.h>
   
   int  g_var = 6;
   char g_buf[]="A string write to stdout.\n";

 int main (int argc,char *argv[])
 {
          int     var = 88;
          pid_t   pid;
   
          if(write(STDOUT_FILENO,g_buf,sizeof(g_buf)-1) < 0)
    	{
		printf("Write string to stdout failure: %s\n",strerror(errno));
		return -1;

        }
	printf("Before fork\n");

	if( (pid=fork()) < 0)
	{
		printf("Create child process failure: %s\n",strerror(errno));
		return -2;
	}

	else if( pid == 0)
	{
		printf("Create child process successful.his PID is[%d] and start running..\n",getpid() );
		g_var++;
		var++;
	}

	else
	{
		printf("Parent process PID[%d] waiting ...\n",getpid() );
		sleep(1);
	}

	printf("PID=%ld,g_var=%d,var=%d\n",(long)getpid(),g_var,var);
	return 0;
 }
